#include "../mqserver/mq_binding.hpp"
#include <gtest/gtest.h>
using namespace wzf;

std::shared_ptr<wzf::BindingManager> bmp;

class BindingTest:public testing::Environment
{
public:
    virtual void SetUp() override
    {
        bmp = std::make_shared<wzf::BindingManager>("./data/test.db");
    }
    virtual void TearDown() override
    {
        // emp->Clear();
        DLOG("clear");
    }
};

// TEST(BindingTest, insert_test)
// {
//     bmp->Bind("exchange1", "queue1", "news.sport.#", true);
//     bmp->Bind("exchange1", "queue2", "news.food.#", true);
//     bmp->Bind("exchange2", "queue1", "news.sport.#", true);
//     bmp->Bind("exchange2", "queue2", "news.food.#", true);
//     ASSERT_EQ(bmp->Size(), 4);
// } 

// TEST(BindingTest, select_test)
// {   
//     std::shared_ptr<Binding> ptr = bmp->GetBinding("exchange1", "queue1");
//     ASSERT_EQ(ptr->exchange_name, "exchange1");
//     ASSERT_EQ(ptr->msgqueue_name, "queue1");
//     ASSERT_EQ(ptr->binding_key, "news.sport.#");
// }

// TEST(BindingTest, select_exchange_test)
// {
//     MsgQueueBindingMap mbm = bmp->GetExchangeBindings("exchange1");
//     ASSERT_EQ(mbm.size(), 2);
//     ASSERT_NE(mbm.find("queue1"), mbm.end());
//     ASSERT_NE(mbm.find("queue2"), mbm.end());
// }
// //删除测试

// TEST(BindingTest, remove_queue_test)
// {
//     bmp->RemoveMsgQueueBindings("queue1");
//     ASSERT_EQ(bmp->Exists("exchange1", "queue1"), false);
//     ASSERT_EQ(bmp->Exists("exchange2", "queue1"), false);
// }

// TEST(BindingTest, remove_exchange_test)
// {
//     bmp->RemoveExchangeBindings("exchange1");
//     ASSERT_EQ(bmp->Exists("exchange1", "queue1"), false);
//     ASSERT_EQ(bmp->Exists("exchange1", "queue2"), false);
// }
// TEST(BindingTest, remove_single_test)
// {
//     ASSERT_EQ(bmp->Exists("exchange2", "queue2"), true);
//     bmp->UnBind("exchange2", "queue2");
//     ASSERT_EQ(bmp->Exists("exchange2", "queue2"), false);
// }


TEST(BindingTest, recovery_test)
{
    ASSERT_EQ(bmp->Exists("exchange2", "queue2"), true);

}
int main(int argc, char* argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new BindingTest);
    int ret = RUN_ALL_TESTS();
    return 0;
} 